package com.wyl.java.thread_.create_;

import cn.hutool.core.util.RandomUtil;


/**
 * 线程的创建
 * 方法一：继承Thread，重写run方法，调用start运行
 * @author 吴宇亮 on 2023/3/24 14:43
 */
public class CreateThread01 extends Thread {

    public static void main(String[] args) {
        Thread thread1 = new CreateThread01();
        Thread thread2 = new CreateThread01();
        thread1.start();
        thread2.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                if (RandomUtil.randomBoolean()) {
                    Thread.sleep(RandomUtil.randomLong(500, 1200));
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        }
    }
}

